iOS 开发笔记(二)

工作不常用但可能需要google的一些知识,整理总结一下,方便以后查找,本文收集的有4点:获取系统当前音量、NSLog宏定义、修改app语言、获取app基础信息。

获取系统音量(iOS6以上可用)

1
[[AVAudioSession sharedInstance] outputVolume]

NSLog宏

1
2
3
4
5
6
7
8
9
#ifdef DEBUG
#define NSLog(format, ...) do { \
fprintf(stderr, "<%s : %d> %s\n", \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
__LINE__, __func__); \
(NSLog)((format), ##__VA_ARGS__); \
fprintf(stderr, "-------\n"); \
} while (0)
#endif

修改应用语言为中文

  1. 选中项目
  2. 选择target
  3. info->Localization native development region->打开下拉选项卡选择china

使用block回调方式接收通知

block回调会retain系统,需要注意循环引用

1
2
3
4
5
6
7
8
9
10
11
__weak typeof(self) weakSelf = self;
[[NSNotificationCenter defaultCenter] addObserverForName:UITextFieldTextDidChangeNotification object:self.userTextField queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
UITextField *textField = note.object;
if (textField.text.length) {
[weakSelf.doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[weakSelf.doneButton setUserInteractionEnabled:YES];
} else {
[weakSelf.doneButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[weakSelf.doneButton setUserInteractionEnabled:NO];
}
}];

获取app信息

1
2
3
4
5
6
7
8
9
10
// app 信息字典
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
// app名称
NSString *app_Name = [infoDictionary objectForKey:@"CFBundleDisplayName"];
// app版本
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
// app build版本
NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];

NSLog(@"%@",infoDictionary);

控制台输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
 {
BuildMachineOSBuild = 17C88;
CFBundleDevelopmentRegion = "zh_CN";
CFBundleDisplayName = "app名称";
CFBundleDocumentTypes = (
{
CFBundleTypeIconFiles = (
"Icon-Small.png",
"Icon.png"
);
CFBundleTypeName = "Aura Config";
CFBundleTypeRole = Viewer;
LSHandlerRank = Owner;
LSItemContentTypes = (
"com.aylanetworks.auraconfig"
);
}
);
CFBundleExecutable = Aura;
CFBundleIcons = {
CFBundlePrimaryIcon = {
CFBundleIconFiles = (
AppIcon29x29,
AppIcon40x40,
AppIcon60x60
);
CFBundleIconName = AppIcon;
UIPrerenderedIcon = 1;
};
};
CFBundleIdentifier = "bundle identifier";
CFBundleInfoDictionaryVersion = "6.0";
CFBundleName = Aura;
CFBundleNumericVersion = 50364416;
CFBundlePackageType = APPL;
CFBundleShortVersionString = "1.0";
CFBundleSignature = "????";
CFBundleSupportedPlatforms = (
iPhoneOS
);
CFBundleURLTypes = (
{
CFBundleTypeRole = Editor;
CFBundleURLSchemes = (
aylacontrol,
AgileLink,
AylaSmartPlug,
auracontrol
);
},
{
CFBundleTypeRole = Editor;
CFBundleURLSchemes = (
"com.googleusercontent.apps.654054971787-coh52to0m9qta3aoj0sjg224c5t4vg0r"
);
},
{
CFBundleTypeRole = Editor;
CFBundleURLSchemes = (
"AylaNetworks.iOS-Aura"
);
},
{
CFBundleTypeRole = Editor;
CFBundleURLSchemes = (
wxe450e4ee1187148c
);
}
);
CFBundleVersion = 3;
DTCompiler = "com.apple.compilers.llvm.clang.1_0";
DTPlatformBuild = 15C107;
DTPlatformName = iphoneos;
DTPlatformVersion = "11.2";
DTSDKBuild = 15C107;
DTSDKName = "iphoneos11.2";
DTXcode = 0920;
DTXcodeBuild = 9C40b;
ITSAppUsesNonExemptEncryption = 0;
LSApplicationQueriesSchemes = (
weixin
);
LSRequiresIPhoneOS = 1;
MinimumOSVersion = "9.0";
NSAppTransportSecurity = {
NSAllowsArbitraryLoads = 1;
NSAllowsLocalNetworking = 1;
};
NSBluetoothPeripheralUsageDescription = "Aura is requesting access to Bluetooth to manage nearby compatible devices.";
NSCameraUsageDescription = "Aura would like to use your camera to scan the QR Code.";
NSLocationWhenInUseUsageDescription = "Aura would like to use your location to fill the coordinates. Please allow the app to use your device's location services.";
UIAppFonts = (
"HelveticaNeue.ttc"
);
UIDeviceFamily = (
1
);
UILaunchImages = (
{
UILaunchImageMinimumOSVersion = "11.0";
UILaunchImageName = "LaunchImage-1100-Portrait-2436h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{375, 812}";
},
{
UILaunchImageMinimumOSVersion = "8.0";
UILaunchImageName = "LaunchImage-800-Portrait-736h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{414, 736}";
},
{
UILaunchImageMinimumOSVersion = "8.0";
UILaunchImageName = "LaunchImage-800-667h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{375, 667}";
},
{
UILaunchImageMinimumOSVersion = "7.0";
UILaunchImageName = "LaunchImage-700";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{320, 480}";
},
{
UILaunchImageMinimumOSVersion = "7.0";
UILaunchImageName = "LaunchImage-700-568h";
UILaunchImageOrientation = Portrait;
UILaunchImageSize = "{320, 568}";
}
);
UIMainStoryboardFile = Login;
UIRequiredDeviceCapabilities = (
arm64
);
UISupportedInterfaceOrientations = (
UIInterfaceOrientationPortrait
);
UTExportedTypeDeclarations = (
{
UTTypeConformsTo = (
"public.data"
);
UTTypeDescription = "Aura Config File";
UTTypeIdentifier = "com.aylanetworks.auraconfig";
UTTypeTagSpecification = {
"public.filename-extension" = auraconfig;
"public.mime-type" = "application/json";
};
}
);
}